home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Toolbox
/
Visual Basic Toolbox (P.I.E.)(1996).ISO
/
techinfo
/
funct-up
/
funct-up.doc
next >
Wrap
Text File
|
1996-03-29
|
64KB
|
1,685 lines
Often Used Functions 1996 File: \VB4\RE1V3\Funct-up.doc
for VB 4.0 16-bit Funct-up.zip
NOTICE: Most of this document is from sections from various user
manuals by Microsoft. Some of it is from books and other from
personal notes. Consider this document copyrighted by various
companies, including some sections by Microsoft. You can use it but
it cannot be sold!
This document is mainly for VB 4.0, but most of it also applies
to VB 3.0.
Function Use and Example
A ░▒░
AddItem box.AddItem. item[,index]
To add items to a list or combo box.
index = where the new item is to be added in the list
Example--- List3.AddItem "Germany"
List3.AddItem "USA", 0 ' place it first
List3.AddItem "France" ' inserted at end or in
' proper sort order
RemoveItem box.RemoveItem. item[,index]
To remove items to a list or combo box.
To remove all items from a list or combo box use
box.Clear, such as List4.Clear .
Sort items (in a box) by setting the Sorted property to True and
omitting the index.
Array see **** ARRAYS **** section
B ░▒░
[form.][control.] BackColor [=color]
[form.][control.] ForeColor [=color]
applies to Form, cmd. button, label, list box, etc.
exa.---- lbl2.BackColor = RGB(10, 10, 240) ' red, green, blue
ByVal used to pass values by value rather than by reference. The
ByVal means the value of the variable is Not changed. It cannot
be used with an Object type or an array.
exa.--- Declare Function GetPfString Lib "Kernel" (ByVal SName$,
ByVal KName$, . . .) As Integer
exa.--- Function DisplayTot ( Gp1A As String, ByVal N4 As Integer)
C ░▒░
CCur( expression) this function converts number to the Currency type
CDbl (expression) this function converts number to the Double type
CDate (expression) this function converts number to the Date type
Examples---
vMyDate = "February 12, 1971" ' define the date
wMySDate = CDate( vMyDate ) ' converts to a Date data type
mPayPerWeek = CCur( hours * hourlyPay )
CLng (expression) to force to a Long data-type
CSng (expression) to force to a Single data-type
[object.]Cls clears the drawing area and area is repainted in
the background color
The object can be a form, picture box, or the
Printer object.
Example--- pctHouse1.Cls ' clear the picture box
Cls ' clear the current form
CStr Convert a number to a string.
(Most conversions are automatic.)
CreateDynaset Method (Pro. Edition only) Creates a Dynaset object
from a specified Table object, QueryDef object or SQL stmt.
Dim MyDB As Database, MySet As Dynaset
Dim MyTable As Table, SQLStmt As String
Const DB_READONLY = 4 ' Set constant.
Set MyDB = OpenDatabase("BIBLIO.MDB") ' Open database.
' Set text for the SQL statement.
SQLStmt = "SELECT * FROM Publishers WHERE State = 'NY'"
' Create the new Dynaset.
Set MySet = MyDB.CreateDynaset(SQLStmt, DB_READONLY)
' *** 2nd example, using a Data control
DatHouses.DatabaseName = "Propt1.mdb"
DatHouses.RecordSource = "House1" ' table
DatHouses.Options = 4 ' ReadOnly
DatHouses.Refresh ' Open the database and set options
Clipboard can hold only one piece of the same kind of info at one
time.
Clipboard.Clear ' clear it
Clipboard.SetText StringData ' send string data to Clipboard
Clipboard.GetText method
Example--- Destin2 = Clipboard.GetText() ' used as function
code to select text---
KeyWord (method) Example
SelStart Text1.SelStart = 0 ' start with 1st char.
SelLength Text1.SelLength = 50 ' take 1st 50 char.s
SelText First50 = Text1.SelText ' text selected
SetText ' send selected text to Clipboard
Sub Copy_Click() ' copy selected text
Clipboard.SetText Text1.SelText
End Sub
Sub Cut_Click() ' cut selected text
Clipboard.SetText Text1.SelText
Text1.SelText = ""
End Sub
SendKeys Statement--- sends one or more keystrokes to the
active window as if typed at the keyboard.
syntax--- SendKeys string [,wait]
See PP. 844-847
[Formname].Controls( index ) is the Controls collection.
All loaded controls on a form are included in the Controls
collection. When there are control arrays on the form, each loaded
element of each array is included in the Control collection.
exa.--- For K2 = 0 To frmAny1.Controls.Count - 1
Count Property (Data Access)
Count returns the number of objects in a collection.
This example lists the names and total number of TableDef and
QueryDef objects in the specified database. Note the two ways to do
this. The second technique does not use the Count property.
Dim MyDB As Database, I As Integer, Td as TableDef
Set MyDB = OpenDatabase("MYDB.MDB")
Debug.Print MyDB.TableDefs.Count
For I = 0 To MyDB.QueryDefs.Count - 1
Debug.Print MyDB.QueryDefs(I).Name ' name of QueryDef
Next I
' Or, without reference to the Count property...
For Each Td In MyDb.TableDefs ' Iterate through each element.
Debug.Print Td.Name ' print table name
Next
Debug.Print MyDB.QueryDefs.Count
D ░▒░
DateAdd Function DateAdd( interval, number, date )
See PP. 221-222 LR
DateDiff Function DateDiff( interval, date1, date2
[,firstdayofweek [,firstweekofyear]] )
See PP. 223-225 LR
DateSerial Function DateSerial( year, month, day)
Example--- MyDate = DateSerial( 1995, 5, 12 ) ' 5/12/1995
DatePart Function
DatePart( interval, date1, [,firstdayofweek [,firstweekofyear]] )
Example--- TestDate = Now - 4 ' subtract 4 days from current
date MsgBox = "Quarter: " & DatePart( "q", TestDate ) & _
" and the day of the year is " & DatePart( "y", TestDate )
DateValue Function DateValue( date )
Example--- MyDate = DateValue( "February 11, 1974" )
' returns a date as a number
See P. 229
Day Function Day( date ) ' returns a number between 1 and 31
DDE Dynamic Data Exchange--- see the DDE section
Debug.Print [items] [;] prints to Immediate pane
exa.--- Debug.Print "Salary = "; Salary1
Dim varname [([subscripts])] [As [New] type]
[,varname [([subscripts])] [As [New] type]] . . .
subscripts pertain to an array variable
type is the data type of the variable, such as Integer or
String
Variables declared with Dim are local variables and their values
disappear when the Module or procedure ends.
An object varaible must be declared with New to create an instance
of that object.
If you do not specify a data or ojbect type, then it is declared as
a Variant type. You can use the Deftype (such as DefInt A-H) in a
module to declare future variables which are not explicitly
declared (by type statements.)
Also see Private and Public.
Dir[$] [Filespec [,attrmask])]
Dir returns a Variant; Dir$ returns a String
String expression that specifies a path or file name. The path
and file name can include a drive specfication and any valid
wildcard characters. (See pp. 142+ of (VB 3) Language
Reference for details.)
Dir1.Path = Drive1.Drive example of setting directory drive to
the drive of the Drive control
Drive1.Drive = Dir1.Path example of resetting drive from dir.
File1.Path = Dir1.Path example of setting file list box path
Do loops
Do While condition
statements
Loop ' tests --before-- each execution of the loop
Do
statements
Loop While condition ' tests after each execution of the loop
Do Until condition
statements
Loop ' tests --before-- each execution of the loop
[control.]Drag action use when DragMode is set to 0 (Manual)
action = 1, initiates Drag method to allow user to drag control.
action = 2, control is dropped; action = 0, cancels the drag
E ░▒░
Error Err ' generates an error (# Err) in your code
Exit Do Exit Property
Exit For Exit Sub
Exit Function
F ░▒░
FileCopy source, destination
Example--- SrcFile = "My1.txt" : DesFile = "B:\Bu1\K2.doc"
FileCopy SrcFile, DesFile
Also see Name (rename file) and Kill (delete file.)
FileLen( filename )
This returns a Long integer that indicates the file length in
bytes.
FileName get filename from dir. and fileList controls
SFile$ = dirList1.Path + "\" + filList1.FileName
Open SFile$ For Input As #2
focus see SetFocus
For counter = start To end (Step increment)
statements
[Exit For]
Next [counter]
Form_Load comes before Form_Activate. Use Form_Activate to
use code for controls on the form.
Format Format[$] ( numeric-expression [,fmt$] )
Format$ function converts a numeric value into a string and
gives you control over the string's appearance.
The Format converts the numeric into a Variant type.
Examples--- (assuming United States is the country in Windows
Control Panel) Result
Total1 = Format$( 8355.4, "00000.00" ) 08355.40
Total1 = Format$( 8355.4, "#####.##" ) 8355.4
Total1 = Format$( 8355.4, "##,##0.00" ) 8,355.40
Total1 = Format$( 8355.4, "$##,##0.00" ) $8,355.40
Total1 = Format$( 8355.4, "Currency" ) 8,355.40
Time and Date--- Result
Format$( Now, "m/d/yy" ) 1/27/95
Format$( Now, "dddd, mmmm dd, yyyy" ) Wednesday, January
27, 1993
Format$( Now, "hh:mm: AM/PM" ) 07:18 PM
Format$( Now, "d-mmmm h:mm" ) 3-April 7:18
Named format---
Format$( Now, "Long Date") ' such as Saturday, April 4,
' 1996
Forms( index ) the syntax for refering to a form array
index must be in the range of 0 to Forms.Count -1
The Forms collection contains all the loaded forms.
FreeFile [( )]
Returns the next valid file number.
Example---
FileNum = Freefile ' get next available file number
Open "Testfile" For Output As FileNum
G ░▒░
GetText destination = Clipboard.GetText()
also see SetText
Global varname [ ([Subscripts]) ] [As [New] type] [, varname . . .
This must be used in the Decalrations section of a code module.
exa.--- Global ar1( 1 To 8 )
Global ar2( 1 To 8, 10 To 20 ) ' 2-dim.; up to 60 dim.
H ░▒░
Hide Method [form.]Hide
Example--- frmTest2.Hide ' hide does Not unload the form
I ░▒░
If condition Then
[statements]
ElseIf condtion Then
[esleIfStatements]
Else
[statements]
End If
InputBox( prompt [,title][,default] [,xpos] [,ypos] [,helpfile]
[,context] )
Example--- OutStr2$ = InputBox( "Enter line of data: ", _
"==Input to File==", "Yes" ) ' gives prompt, title and default
Int( number ) get the integer portion of a number
IsNumeric Find out if the variable is numeric.
If IsNumeric( x2 ) Then . . .
IsDate To determine if the Variant variable contains a value
that can be converted to a date/time value.
IF IsDate( Text1.Text ) Then
SomeDate = DVDate ( Text1.Text )
. . .
IsEmpty To determine if a Variant variable has the Empty value.
IF IsEmpty( X2 ) Then X2 = 0
J ░▒░
K ░▒░
Kill pathname deletes 1 or more files
Example--- Kill "B*.txt"
L ░▒░
LBound Functions returns the smallest available subscript for the
indicated dimension of an array.
syntax--- LBound( arrayname [,dimension] )
Example--- sLBound1 = LBound( arNames, 1 )
LCase (string) returns string in lower case
Like opterator (SQL)
exa.--- If Not (td.name Like "MSys*") Then . . .
Line Continuation character is the space and underscore ( _). No
comments can be placed after the Line Continuation character.
Use the colon to separate different statement on the same line.
Example--- Text4.Text = "Hello" : Red = 255
Like Operator (SQL) Expression Like "patter"
Example---
If Not( Td.Name Like "MSys*" ) Then . . .
[object.]Line [ [Step] (x1,y1)] - [Step] (x2,y2) [,[color][,B[F]] ]
Example---
Sub Form_Click ()
Dim x1!, X2!, Y1!, Y2!, Color1 As Integer, Color2 As Integer
x1 = 50 : y1 = 90 : x2 = 2500 : y2 = 1900
DrawWidth = 20
Color1 = RGB( 0, 0, 255 ) ' blue
Color2 = RGB( 80, 0, 255 ) ' blue & some red
Line (x1, Y1) - (x2, Y2), Color1 ' draw on form
x1 = 850 : y1 = 890 : x2 = 5500 : y2 = 6500
Line (x1, Y1) - (x2, Y2), Color2
End Sub
See also Circle Method, DrawMode Property, and Shape Control.
control.ListCount for ListBox and ComboBox
exa.--- txtBox1.Text = Lst1.ListCount ' number of items in list
Load object
Loads a from or control into memory. A copy of the form or control
must exit at design time.
Example--- This assumes that text box called txtField1 exits and
set its Index property to 0, and defined TotalCopies as an integer
greater than 0.
Sub Form_load ()
For I = 1 To TotalCopies
Load txtField1( I ) ' load a copy, in control array
txtField1( I ).Top = txtField1( I -1 ).Top + 500 ' Move
' copy
txtField1( I ).Visible = True
txtField1( I ).Text = "Field " + Format$( I ) + " "
Next I
End Sub
Loop Structures--- ░▒▓▒
Do While condition ' ******
statements
Loop ' ******
Another variation of the Do...Loop statement executes the
statements first and then tests the condition after each execution.
Do ' ******
statements
Loop While condition ' test at end of Loop ******
The Do Until is equivalent to Do While Not.
Do Until condition ' ******
statements
[Exit Do]
Loop ' ******
For counter = start To end [Step increment] ' ******
statements
[Exit For]
Next [counter] ' ******
Example of For...Next Loop---
For K2 = Beg1N To End1N Step 2 ' ******
statements
Next K2 ' ******
A For Each...Next loop repeats a group of statements for ech
element in a collection of objects or in an array.
For Each element In group ' ******
statements
Next element ' ******
Example--- For Each TableDef In objDb.TableDefs()
List2.AddItem TableDef.Name
Next TableDef
With variables and arrays, the type must be Variant.
( See P. 141 in PG )
M ░▒░
Merge text into your code
Use the Insert menu, choosed File. (see P. 88 in PG)
Mid[$] ( stringexpr, start [,length] )
Mid returns a Variant; Mid$ returns a String
Mouse buttons
Exa.--- Sub Form_MouseDown( Button As Integer, Shift As Integer,
X As Single, Y as Single)
If Button = 1 Then Print "Left button pressed"
If Button = 2 Then Print "Right button pressed"
If Button = 3 Then Print "Middle button pressed"
If Shift And 1 Then Print "You pressed the Shift key."
If (Shift And 3) = 3 Then Print "pressed the Shift and Ctrl."
With MouseMove, the complete state of the mouse buttons is used.
Exa.--- Sub Form_MouseMove( Button As Integer, Shift As
Integer, X As Single, Y as Single)
If Button = 1 Then Print "Only the Left button was pressed."
MsgBox Example--- MsgBox Msg1, Type1, Title1
(See the Special Dialog Boxes section for details.)
N ░▒░
Name oldpathname As newpathname renames a disk file or subdir.
Example--- OldFile = "Mb2.txt" : NewFile = "Mkg22.txt"
Name OldFile As NewFile
O ░▒░
On Error { GoTo line | Resume Next | Goto 0 )
Usually use a line label for the "line" parameter.
Open pathname [For mode] [Access access] [lock] As [#]filename
Example--- Open vPathFile1 For Input As #3 (seq. file)
Example of Random access file---
Open file For Random As Filenumber Len = recordLen
Type Record1
ID As Integer
FirstName As String * 18
LastName As String * 22
CoName As String * 35
End Type
Dim MyRecord As Record1 ' set variable for later fields input
Open "Test2.rnd" For Random As #2 Len = Len( MyRecord )
[statements]
Get #2, 10, MyRecord ' place contents of 10th record into
' the variable MyRecord
MyRecord.FirstName = "Ken" ' use property to set field value
MyRecord.LastName = "Sumerford"
Put #2, 15, MyRecord ' fill available fields with output data
LastRecord1 = LOF(2) \ Len(MyRecord)
LastRecord1 = LastRecord1 + 1 ' new rec.#
Close #2
Close ' to close all open seq. and random files
A random access file can hold from 1 to about 16.7 million records.
Example of binary file--- (like a random access file, you can both
read and write to an openned binary file)
Open FileName4 For Binary As #4
In the 32-bit version, you cannot use the Imput$(,) for picking up
indivdual bytes from a file. Instead, use byte array for both
16-bit and 32-bit app.s. Example---
Dim bytX() As Byte ' byte array
Open "MYFIL.TXT" For Binary Access Read Write Lock Write As #1
ReDim bytX(1 To LOF(1)) As Byte
Get #1, 5, bytX() ' get info in binary format from
' file #1 and record #5
' now you need to use the byte array
See PP. 650-651 LR
Option Base {0 | 1} to set the lower bound in an array
Option Compare {Binary | Text} with Text, AA = aa
Option Explicit use this to make sure variables are declared.
This option can be used at the class, form or standard module level.
P ░▒░
Print method--- [object.]Print [{Spc() | Tab(n)}]
[expressionList] [ { ; | , } ]
Examples--- MainForm1.Print " This is a form called MainForm1 "
picSMsg.Print " This is a picture box. "
Print " This is the current form. "
Printer.Print "This text is going to the printer. "
picSMsg.Print " The value of X2 is "; X2; " in the equation."
(The comma (,) skips to the next print zone (which is 14
columns wide).)
Example---
frmTest4.FontName = "MS Sans Serif"
frmTest4.FontSize = 10
frmTest4.Print "First Name ", "Last Name", "Phone # "
frmTest4.Print
frmTest4.Print "John ", "Vanderbilt ", "567-4500 "
frmTest4.Print "Mary ", "Hall ", "567-2376 "
frmTest4.Print "Scott ", "Strongman ", "890-5077"
Exa.--- NL = Chr(13) + Chr(10) ' new line char. ░▒░
Txt1 = "This should be on " & NL & "two lines. "
picShw1.Print Txt1
picShw1.Print Tab(30); "This print starts at col.# 30."
By default, each Print method prints the text and then moves down
to the next line. However, by placing a semicolor or a comman at
the end of the first statement, you cause the output of the next
statement to appear on the same line. The comma places text at the
next print zone (14 char.s by default.)
Also see TextHeight and TextWidth methods.
Printer Object Printer Printers(index) is Printers collection
Printer properties include Font, FontBold, FontItalic, FontSize,
FontName, FontUnderline, ScaleTop, ScaleLeft, PrintQuality, Copies,
CurrentX, CurrentY, and Page
The ScaleHeight and ScaleWidth properties define the size of the
printable area of the page.
Exa.--- Printer.FontSize = 12 : Printer.CurrentX = 400
Printer.Print "Time Card"
Printer.Line (50,80) -Step(300,400)
Printer.EndDoc ' sent all print to printer and formfeed
Printer methods include Circle, Line, Print, NewPage, EndDoc,
KillDoc, PaintPicture, and Scale.
PrintForm Method prints the contents of the current form to
the printer. syntax--- [from.]PrintForm
Exa.--- frmMK1.PrintForm ' send form to printer
Private varname [([subscripts])] [As [New] type]
[,varname [([subscripts])] [As [New] type]] . . .
Used at module level to declare private variables and allocate
storage space. Private is also used to declare the object type
of a variable. (Example--- Private Ws1 As New Worksheet )
Public varname [([subscripts])] [As [New] type]
[,varname [([subscripts])] [As [New] type]] . . .
Variables declared using the Public statement (at the module
level) are available to all procedures in all modules in all
applications. However, Public cannot be used in a class
module to declare a fixed-length string variable. A Public
statement cannot be used in a procedure.
See also Private and Static.
Properties---
Properties that you can set and get ar run time are called
read-write properties. Properties that you can only read at run
time are called read-only properties. See PP. 187-188 PG
Q ░▒░
Quotes
VB 4 interprets two quotation marks in a row as an embedded
quotation mark.
Example--- Nt1 = "The man said, ""Get out now."" and ran."
Using quotes in Objects is tricky. For example, this will work:
NewDB1 = "C:\VB4\RE1V3\PCV3.MDB"
set dbPCV = ws1.CreateDatabase(NewDB1,dbLangGeneral)
R ░▒░
Randomize Seed random number generator.
RGB (red, green, blue) each color must be from 0 to 255
Color RGB value Red Green Blue
blue &HFF0000 0 0 255
green &HFF00 0 255 0
cyan &HFFFF00 0 255 255
red &HFF 255 0 0
yellow &HFFFF 255 255 0
white &HFFFFFF 255 255 255
Rnd[(number)] The argument number can be any valid numeric
expression. The Rnd function returns a Single
value > 0 and < 1.
Examples--- X2 = Int( Rnd * 100 +1 ) ' generates a number
' between 1 and 100
upper1 = 100 ' upper bounds for the returned number
lowerBounds1 = 50
X4 = Int( (upper1 - lowerBounds1 +1) * Rnd + lowerBounds1 )
X5 = Rnd 1 ' take the next random number in the sequence
Recordset ░▒▓▒ examples & notes ░▒▓▒
WARNING: You must set the path and filename for the .ini
file for setting such things as CollatingSequence for the
DBEngine. Example---
DBEngine.IniPath = "C:\WINDOWS\VB.INI"
Set ws1 = DBEngine.Workspaces(0) ' this is the default ws
Set db1 = ws1.OpenDatabase("c:\smdb\p45", False, False, _
"Paradox 4.x;")
MsgBox "CollatingOrder " & db1.CollatingOrder
Set rs1 = db1.OpenRecordset("Prospect")
CANNOT-- rs1.Index = "Prosp num" ' PK, establish sort order
If you have a data control to set database and recordset,
then you can just include the .IniPath statement.
Example--- DBEngine.IniPath = "C:\WINDOWS\VB.INI"
Open a database---
datSSM.DatabaseName = "\VB3\SSM1.MDB" ' db openned, rs rebuilt
datSSM.RecordSource = "Customer1" ' rs (recordset) rebuilt
datSSM.Refresh ' rs (recordset) rebuilt
' this will fail if the db name is invalid
If datSSM.Database Is Nothing Then
MsgBox "Open Failed (Database is invalid) ", , "Failed"
End If
If datSSM.Recordset Is Nothing Then
MsgBox "Open Failed (Recordset is invalid) ", , "Failed"
End If
Add a New record with AddNew method
If (datProsp(1).Recordset.Updatable = True) And _
(datProsp(1).ReadOnly) = False Then
datProsp(1).Recordset.AddNew ' add new record
datProsp(1).Recordset.("Title") = "President" ' field value
datProsp(1).Recordset.("Sale Price) = 45.95
txtCoName.Text = "XY Company" ' chg data-bound control
datProsp(1).Recordset.Update ' update database (with change)
Else ' database file cannot be updated
MsgBox "The database file cannot be updated"
Exit Sub
End If
' * * * VB makes no attempt to validate primary or foreign
' keys. Use the data control's Validate event.
Show all fields in a recordset---
For K1 = 0 to datVdr.Recordset.Fields.Count - 1
lstFlds.AddItem datVdr.Recordset(K1) ' add field to list
Next K1
Error Handling--- The Error event is passed a DataError argument
(a number.) A text string explaining the error can be found by
using the Error$( DataErr) function.
Strings exceeding 64 K bytes (limitation of VB string variables)
can be handled in a Memo field by using FieldSize, GetChunk,
and AppendChunk.
Update a record and Close it
' use datPros1.Edit if Not in Edit for rs
datPros1.Recordset.Update
datPros1.Recordset.Close
another example---
datProspect1.Recordset.Edit ' Enable editing
datProspect1.Recordset.Update ' save edits
* * * You can add, change and save-to-file a picture by
using a data-bound Picture box or image control. Also see
the LoadPicture and SavePicture statements.
Delete a record (Also see code later in this section.)
datPros1.Recordset.Delete
If datPros1.Recordset.EOF = False Then
datPros1.Recordset.MoveNext
Else ' now at the last record
datPros1.Recordset.MoveFirst
End If
Check for a valid record pointer---
If (datPros1.Recordset.BOF = False) AND _
(datPros1.Recordset.EOF = False) Then ' current record
' pointer is valid unless you have not moved after deleting
' the last record in the recordset
Else ' invalid position for current record pointer
. . .
End If
Move Method (data access) ---- recordset.Move rows [,start]
rows is a Long integer, positive for move forward
start is a String value identifying a bookmark
datPros1.Recordset.Move 10 ' move 10 rows forward
Move to first or last record in the recordset
datPros1.Recordset.MoveFirst
datPros1.Recordset.MoveLast
Move to next or previous--- use MoveNext or MovePrevious
datPros1.Recordset.MoveNext
Get value of a field * * *
aLName = datPros1.Recordset.Fields( "P lname").Value
If you use a Move method that moves beyond BOF or EOF, VB generates
a trappable error. The following code protects against this:
Do While datPros1.Recordset.EOF = False ' Assuming EOFAction =1
datPros1.Recordset.MoveNext
' insert code to work with current record
Loop
datPros1.Recordset.MoveLast ' reposition to a valid record
Note--- The MoveNext method and a Loop can be used like a Scan.
BookMark
Use BookMark to mark a record and later find it. (You cannot use
the Refresh method during after setting the Bookmark, or you will
loose the position.)
Dim MyBMark As Variant
MyBMark = datPros1.Recordset.BookMark ' save current rec.
' pointer
datPros1.Recordset.MoveFirst ' move off record
datPros1.Recordset.BookMark = MyBMark ' move to bk.mark
Finding records----
To locate records you use the Find methods with dynaset- and
snapshot-type Recordset objects, and the Seek method with
table-type Recordset objects.
VB 4 supports these Find methods:
FindFirst method finds the first record meeting the criteria
FindLast method
FindNext method finds the next record meeting the criteria
FindPrevious method
aGender1 = "Mr."
datPros1.Recordset.FindFirst "Mx = " & aGender1 'find value
' in the [Mx] field
Check the value of the NoMatch property to see if a match was
successful.
vHere = rs2.BookMark ' set to current rec. in Recordset
aMyCriteria = "State = 'NY'" ' set criteria, field is State
rs2.FindFirst aMyCriteria
If rs2.NoMatch Then
rs2.BookMark = vHere ' match not made, go to bk.mark
Else
' match found
. . .
End If
Determine whether data in Recordset can be changed---
If (datPros1.ReadOnly = False) And
(datPros1.Recordset.Updatable = True) Then
. . . ' OK to change data in rs
Determine if data in the field can be changed---
If datPros1.Recordset.Fields("FirstName").Attributes _
And dbUpdatableField = 0 Then
MsgBox "Current field cannot be changed."
End If
Adding a New record---
dat4.DatabaseName = "BIBLIO.MDB" ' Access-type d.b.
dat4.RecordSource = "Titles" ' set table
dat4.Refresh
dat4.Recordset.AddNew ' create a new record
' set field values
dat4.Recordset("Title") = "The Data Control"
dat4.Recordset("PubID") = 43
dat4.Recordset.Update ' Append new record
. . .
dat4.Recordset.Close
The best way to validate fields is by using the data control's
Validation event. Also see info about the Relation object.
Editing the Current record
' open database and recordset first
dat4.Refresh
dat4.Recordset("PubID") = "5007" ' change the value
txt3.Text = "New book title" ' change value in
' bound control
dat4.Recordset.Update
dat4.Recordset.Close ' close rs
Editing the Value of a Field
The set of all Field objects for a Recordset is called the
Fields collection. Here are some examples---
dat4.Recordset.Fields("PubID").Value
dat4.Recordset.Fields("FName") ' refers to Value of [FName]
aName1 = "FName"
dat4.Recordset.Fields(aName1) ' refers to Value of [FName]
dat4.Recordset("FName") ' refers to Value of [FName]
The following shows all fields in the Recordset:
Dim Fld1 As Field
For Each Fld1 In dat2.Recordset.Fields
Lst2.AddItem Fld1 ' add the field to List box
Next Fld1
Deleting Records---
' example of deleting all records less than 1989
dat3.DatabaseName = "Books1.MDB" ' set db name in data control
dat3.RecordSource = "Select * From Titles Where _
[Year Pub] < 1989;"
dat3.Refresh
Do While dat3.Recordset.EOF = False
dat3.Recordset.Delete ' delete current record
dat3.Recordset.MoveNext
Loop
Memo Fields---
Memo fields can handle string that exceed the 64K size
limitation of VB string variables. See the GetChunk method for
further info.
Close Database and Recordset---
Databases and their recordsets are automatically closed when
(1) you use the Close method with the only or last recordset;
(2) the form containing the data control is unloaded; or (3)
the End statement is used. Ways 1) and 2) trigger the Validate
event.
Transactions---
A transaction is a recoverable series of changes you make to a
recordset. The database must also support transactions.
(See PP. 584-586 PG)
Example---
Dim MyTable As Recordset, MyWorkspace As Workspace
Set MyWorkspace = Workspaces(0) ' Set Workspace variable.
' Assume data control's Recordset is from Titles table.
Set MyTable = Data1.Recordset ' Set Recordset variable.
MyWorkspace.BeginTrans ' Start of transaction.
Do Until MyTable.EOF ' *******
If MyTable![PubID] = 5 Then
MyTable.Edit ' *** Enable editing.
MyTable![PubID] = 6 ' Change title.
MyTable.Update ' Save changes.
End If
MyTable.MoveNext
Loop ' *******
If MsgBox("Save all changes?", vbQuestion + vbYesNo, _
"Save Changes") = vbYes Then
MyWorkspace.CommitTrans ' Commit changes.
Else
MyWorkspace.Rollback ' Undo changes.
End If
░▒▓▒ end of Recordset section =======================
RemoveItem box.RemoveItem. item[,index]
To remove items to a list or combo box.
To remove all items from a list or combo box use
box.Clear, such as List4.Clear .
S ░▒░
Select Case testExpression
[Case expressionlist1
Statementblock-1]]
[Case expressionlist2
Statementblock-2]]
[Case Else
Statementblock-n]]
End Select
You can have a list or ranges in the Case statement.
Example--- Case "everything", "nuts" To "soup", TestItem4$
[Form.]Show [style]
Form is the form or MDI form to display.
style = 0 is modeless
style = 1 is model (no VB code after the Show method is executed
until the form is hidden or unloaded)
Also see Hide method.
SetFocus Method object.SetFocus
Example--- txtEditName.SetFocus ' set focus to TextBox
See P. 854 LR
Clipboard.SetText data [,format] SetText copies text on to the
Clipboard, replacing any previous text in the Clipboard.
GetText destination = Clipboard.GetText()
Sequential files--- good for editing text files
Open file For [Input | Output | Append] As filenumber Len =
buffersize
Exa.--- FileNum1 = FreeFile ' get next available file #
file3 = "\VB3\exam4.txt" ' file name, including path
FileSz1 = FileLen(file3)
Open file3 For Append As FileNum1 Len = FileSz1
Print #FileNum1, txtBx1.Text ' write contents to file
' write to a file, output has quotation marks around string
' and commas between fields
Write #2 St3$, AnyW4, AnyNum1%
(Also see Random and Binary access files. See Open stmt.)
Static varname [([subscripts])] [As [New] type]
[,varname [([subscripts])] [As [New] type]] . . .
Variables declared with the Static statement retain their values
during the session. When declared in a procedure, they are local
to that procedure. To make all variables in a procedure static,
use the Static Keyword at the beginning of the procedure.
(Example--- Static Function RunTotal( num1 )
Str[$] (number)
The Str function returns the string representation of a number.
Examples--- M1String = Str( 459.1 ) ' returns " 459.1"
M1String = Str(-459.1 ) ' returns "-459.1"
Str returns a Variant; Str$ returns a String var.
StrConv function returns a converted string
StrConv( string, conversion )
string is the string expression
conversion is the sum of the values for type of conversion
Some conversion settings are---
vbUpperCase convert string to uppercase
vbLowerCase convert string to lowercase
vbProperCase convert string to upper case for
first letter in each word
PROCEDURES----
Sub Procedure syntax---
[ Private|Public ] [Static] Sub procedureName (arguments)
statements
[Exit Sub]
. . .
End Sub
Sub procedures can be placed in standard modules, class modules,
and form modules. They are Public in all modules by default.
A general procedure tells the application how to perform a certain
task. An event procedure is invoked when an event occurs.
Example of calling a Sub procedure---
prFindCo LName, CoName1A ' 2 arguments follow the proc name
Sub Procedures are Public by default and local variables are not
preserved between calls.
Sub Procedures that have variables that are Not declared are local,
unless the variables are declared at a higher level. Is is usually
best to declare, such as with a Dim statement, local variables
within a procedure.
Function Procedure
syntax--- [ Private|Public ] [Static] Function procedureName
(arguments) [As type]
statements
[Exit Function]
. . .
End Function
Example---
Function Hypotenuse (A, B)
Hypotenuse = Sqr( A ^2 + B ^2 ) ' value is assigned to proc
' name
End Function
Hp2 = Hypotenuse (Width1, Height1)
Label3.Caption = Hp2
Examples--- (other ways to call a Function proc, such as ToDec)
Print 10 * ToDec
If ToDec > 20 Then Debug.Print " Out of Range"
ToDec DueAmt1D
Property Procedures are used to create and manipulate custom
properties. (See pp. 120-126 PG)
Once a name is used for a Property procedure, that name cannot be
used to name a Sub or function procedure, or a variable.
Read-Only properties are useful when (1) you want the property to be
read-only for users or (2) you want related code to be executed when
the property is set.
Procedures in Forms
All calls from outside the form module must point to the form
module containing the procedure.
Example--- Form2.SomeSub Argu4, Argu5 ' call sub Procedure
' from form Form2
Procedures in Standard Modules
A call to a common procedure from the same module runs the
procedure in that module. If you call a procedure from another
module, it is best to include the procedure's name (because the
proc name may not be unique.)
Example--- Module2.CName( Argu5, Argu7 )
Passing Arguments to Procedures
The arguments for procedures have the Variant data type by default.
You can declare data types.
Example--- Function DisplayTot ( Gp1A As String, ByVal N4 As
Integer)
Dim Header1 As String, I2 As Integer
. . .
End Function
If the ByVal keyword is used, the original variable is Not changed
by code in the procedure. The ByRef is the default. The Optional
keyword indicates that the arguments are not required, but the Type
must be Variant. ( Example--- Private Sub prShowCo ( Optional
prShw As Variant, Optional ByVal Co1 As Variant, Optional City1
As Variant ) If Optional is used, then all subsequent arguments in
arglist must also be declared as Optional.
Using the ParamArray keyword allows you to specify that a procedure
will accept an arbitrary number of arguments. (See P. 133 PG)
Named Arguments--- For many VB built-in functions, statements, and
methods, VB provides the option ofusing named arguments for
argument values. Example---
Set CurDB = OpenDatabase( exclusive:= False, _
source:= "Fox 2.5", dbname:= "C:\FoxData" )
░ ░ ▒ SQL (some statements and syntax)
CREATE TABLE
CREATE INDEX
ALTER TABLE Alter the structure of an existing table
exa.---
SQL1$ = "ALTER TABLE [DB Books] ADD COLUMN [ISBN] Text(20)"
MyDB1.Execute SQL$
SELECT creates a recordset from 1 or more tables
INSERT transfers a batch of data into the database
exa.--- INSERT INTO [Genled].* SELECT [Trans1].*
FROM [Trans1]
UPDATE changes the data values of a particular set of records
exa.--- UPDATE [Products1] SET [Price] = [Price] * 1.08,
[S Price] = [S Price] * 1.04 WHERE [Rec Date] > #02/15/95#
DELETE deletes records from the database
------------------
SELECT selects fields and records
exa.--- SELECT Prosp1.FirstName, St1.State FROM
[Prosp1], [St1] WHERE Prosp1.State1 St1.State
exa.--- SELECT * FROM [Customer1]
exa.--- SELECT TOP 10 PERCENT * FROM [MyTable]
FROM
WHERE ... WHERE [My Field] = 'NY' ' exact match
... WHERE [My Field] = #??/04/96# ' for 04/96
... WHERE [My Field] LIKE 'S???R' ' matches pattern
... WHERE [My Field] = 4 AND [State] = 'TX'
... WHERE [My Field] BETWEEN 50 And 100 ' a range
GROUP BY combines records with identical values in the specified
field list into a single record
HAVING the having is relevant only to the Group By clause
exa.--- SELECT * FROM Accounts GROUP BY Type1 HAVING
[Trans date] >= #05/01/96#
ORDER BY determines the sort order
exa.--- SELECT * FROM [MyTable] WHERE [Last Name]
LIKE 'S*' ORDER BY [Last Name], [First Name]
exa.--- SELECT TOP 10 PERCENT * FROM [MyTable]
AVG AVG( expression ) AS
exa.--- SQL2 = "SELECT AVG( [Amt1] ) AS [SUM1] FROM Accts
WHERE [Due Date] > #06/01/96#
COUNT CONT( expression) AS tempName
exa.--- SQL3 = "SELECT COUNT(*) AS [Count1] FROM
Prospect1 WHERE [Zip] LIKE '762*'
SUM SUM( expression ) AS resultField
exa.--- SQL3 = "SELECT SUM( [Amt1] ) AS [Sum3]
FROM Accts WHERE [Amt1] > 49 "
T ░▒░
Type Statement used at module level to define a user-defined data
type containing one or more elements. They must be initially defined
only at the (code) module level. Also called Structures.
syntax--- [Private|Public] Type varname
elementName [ ([subscripts]) ] As Type
[ elementName [ ([subscripts]) ] As Type ]
. . .
End Type
Example--- (Type can also be used as a record type.)
' Declarations in a standard (code) module
Private Type SystemInfo ' create the type
CPU As Variant
Memory1 As Long
Cost1 as Currency
PurDate As Variant
End Type
Dim MySystem As SystemInfo ' dimension MySystem
MySystem.CPU = "486" 'assign value to variable
User-defined types can also contain objects. Example---
Private Type AccountPack
frmInput As Form
dbPayRollAcct As Database
End Type
See PP. 177-180 PG
U ░▒░
Unload object
The argument object is the form or control array element to unload.
Unload cannot be used to remove a control created at design time.
exa.--- Unload Me ' unload this instance of a form
Unload optBook(4) ' unload control that was created at r.t.
Updating the Data---
There are 4 ways to update data:
Update method Updates (saves) the changes to the recordset.
UpdateRecord Updates database recordset with data from
bound controls. No events (including
Validate) are triggered when this method is
called.
UpdateControls Updates database recordset changes to
bound controls.
Refresh Creates a new recordset based on
data control properties.
V ░▒░
Val function returns the numbers in a string
Val( string )
Validate event---
The data control's Validate event allows you to check any changes
made to the recordset --before-- newinfo is written to the
database. The AddNew, Update and Move methods trigger Validate,
but not UpdateRecord. (See PP. 586-588 PG)
Example---
Private Sub datExample1_Validate(Action As Integer,
Save As _ Integer) ' Validate entry Before it affects db
If Action = vbDataActionDelete Then ' Delete record
If datExample1.Recordset.RecordCount < 3 Then
MsgBox "Must have at least 2 records in table. "
Save = 0 ' Update will Not be done
Else
Save = 1 ' set Save to True
End If
End If
End Sub
Action argument values (a few)
Value Description
0 Cancel the action that caused the event
(This mostly affects the cursor and not whether the
data is saved to the database.)
1 MoveFirst method
2 MovePrevious method
3 MoveNext method
4 MoveLast method
5 AddNew
6 Update (not UpdateRecord)
7 Delete method
VarType( varname ) Returns a value indicating the subtype
of a variable.
Return Values----
Constant Value Variable type description
vbEmpty 0 Empty (uninitialized).
vbNull 1 Null (no valid data).
vbInteger 2 Integer.
vbLong 3 Long integer.
vbSingle 4 Single-precision floating-point number.
vbDouble 5 Double-precision floating-point number.
vbCurrency 6 Currency.
vbDate 7 Date.
vbString 8 String.
vbObject 9 OLE Automation object.
vbError 10 Error.
vbBoolean 11 Boolean.
vbVariant 12 Variant (used only with arrays of Variants).
vbDataObject 13 Non-OLE Automation object.
vbByte 17 Byte
vbArray 8192 Array.
Note These constants are specified by Visual Basic for
applications. As a result, the names can be used anywhere in your
code in place of the actual values.
Remarks
The VarType function never returns the value for vbArray by itself.
It is always added to some other value to indicate an array of a
particular type. The constant vbVariant is only returned in
conjunction with vbArray to indicate that the argument to the VarType
function is an array of type Variant.
W ░▒░
With can be used in a user Type (Record) or with Objects and
properties.
Examples---
With typeProsRecord
.FirstName = "Sam"
.LastName = "Taylor"
End With
With txtBox2
.Height = 2000
.Wideth = 1800
End With
X ░▒░
Y ░▒░
Z ░▒░
NAMING VARIABLES & CONTROLS ***********************************
Data Types---
DefStr A-H ' String
DefInt I-L ' Integer
DefCur M ' Currency
DefSng N ' Single
DefBool T ' Boolean for True or False (0 = False)
DefVar U-V ' Variant
DefDate W ' Date
DefSng X-Z ' Single
Constants--- See PP. 155-157 PG
In VB 4.0, constant names are in mixed-case format, with a prefix
indicatingg the object library that defines the constant.
vb indicates a constant from the VB and VB for applications
object libraries, such as vbTileHorizontal
db indicates a constant from the data access object library
con indicates a constant that you have created or imported
from another file
You cannot modify a constant or assign a new value as with a
variable.
syntax--- [Public|Private] Const constantName [As type] =
expression
Examples---
Const conPi = 3.14159
Public Const conPi = 3.14159, conWorldPop = 6E+09
Const conRelDate = #2/15/96#
Procedures---
regular (sub) procs begin with pr
my created functions begin with fn
Classes, your created classes mostly
Use cls as the front of the Class Module name, such as
clsRSystem
***********************************
Data Types in VB 4.0 ********
Type-
declaration
Type Description character Range
Integer 2-byte integer % -32,768 to 32,767
Long 4-byte integer & ~ -2,147,000,000 to
~ 2,147,000,000 to
Single 4-byte floating- ! ~ -3.4028E38 to -1.401E-45
point number ~ 1.401E-45 to 3.4028E38
Double 8-byte floating- # ~ -1.79769 D308 to -4.940656D-324
point number ~ 4.9406 D-324 to 1.79769 D308
Currency 8-byte number @ ~ -922,337,000,000,000.5808 to
with fixed decimal ~ -922,337,000,000,000.5807
point (supports up to 4 digits to the
right of the decimal point and
15 digits to the left)
String String of $ 0 to approx. 65,500 characters
characters String is variable-length by
default, but you can make them
fixed by using String * size. For
example--- Dim Empname As String * 40
Variant Date/time, (none)
floating point
number, or string
Byte 1 byte 0 to 255
If the variable contains binary
data, declare it as an array of the
Byte data type.
Boolean 2 bytes True or False
Examples---
Dim I2 As Integer, Amt3 As Double
Static FirstName As String
Global AmtPaid As Currency
Dim DateCur, DateFirst (Variant type)
Dim K2!, K3!, Amt4@
Dim EmpName As String * 50 ' string with 50 char. in length
Function CalcTotPay (Amt1 As Currency, Hrs2 As Integer)
. . .
Sub PaySum ( (V3), Hours5 As Integer ) ' parenthese turns
' V3 into an expression, so no mismatch problems
Function AmtPaid2 (S1 As String, ByVal n1 As Integer) As String
' the return value for this function is a String
******** ARRAYS ***************************
Local fixed arrays must be Static.
Dimensioning of Arrays---
Examples--- Dim Sums( 20 ) As Double
Static Cnt1( 3 ) As Integer ' 4 elements
explicity set lower and upper bounds
Dim Sums( 100 to 120 ) As Currency ' set bounds
Dimension multidimensional array
Dim MultiD( 1 To 10, 1 To 25 ) ' 2 dimensions
Dimension a dynamic array
Dim DynTotals() ' empty dimension list
ReDim DynTotals( X2 + 1 ) ' allocate elements,
' this must be done within a procedure
ReDim DynTotals( X2, 9, 4 ) ' allocate elements,
' This must be done within a procedure.
' This is a multidimensional array. A dynamic
' array created in a proc is limited to 8
' dimensions.
ReDim Preserve DynEmpNames( UBound(DynEmpNames) + 5)
' preserve the values from the current array
' and add 5 elements (you can only add to
' the upper bounds with Preserve)
ReDim MultiD( 1 To 10, 15 To 20 ) ' 2 dimensions
ReDim Preserve MultiD( 1 To 10, 15 To 29 )
' 2 dimensions, only the last upper bound
' can be changed in a Multidimensional array
' when using the Preserve keyword
Huge Arrays
Arrays whose total size exceeds 64K bytes are called huge arrays.
You cannot create huge arrays of object variables or
variable-length strings (fixed-length strings are allowed.)
VB create huge arrays automatically when the array size exceeds
64K bytes. The maximum size for a Huge Array is 64 MB in
enhanced-mode Windows and 1 MB in standard-mode Windows.
The maximum bounds for any array are -32,700 to 32,700 for each
dimension.
Use a dynamic array, instead of a fixed array, to conserve memory.
*************** End of Arrays ********************
Declaring an Object Variable
{Dim | ReDim, | Static | Global} variableName As [New] objectType
(The New can only be used with a specific Form variable.)
example--- Dim FormVar1 As New frmMain ' specific form
example--- Dim FormVarSave As Form ' generic form, no New
example--- Dim SpecText1 As TextBox ' but Not from a
' specific Text Box
examples--- Dim grdControl As Grid ' declare Grid-type
' control variable
Dim House() As Image
ReDim House(10) As Image
using Set Statements
example--- Dim Bal As TextBox ' general declaration
' Bal has an initial value of Nothing
Set Bal = frmAccountDisplay!txtAccountsBalance
' to shorten Form!Control
If Bal.Text < 0 Then
Bal.BackColor = 0
Bal.ForeColor = 255
End If
example--- Set frmEnabledTime = Nothing ' clear memory
' of control variable for global, module-
' level, or static variables
using Is operator
{If | ElseIf} TypeOf object Is objecttype Then
example---
Sub imgTool2_DragDrop (Source1 As Control, x As Single,
Y As Single)
If Source1 Is imgTool2 Then
MsgBox "Cannot drop control on itself."
Else
' do something with dropped control
End If
End Sub
using TypeOf operator (cannot be used with Select Case)
{If | ElseIf} TypeOf object Is objecttype Then
example--- If TypeOf Source1 Is Image Then . . .
True or False
Boolean properties have a value of -1 for True and 0 for False.
VB interprets any value other than -1 or 0 as True.
Keys, special keys in working with VB 3.0 and 4.0
[F8] = Single step
[Shift][F8] = Procedure step
[F9] = toggle Breakpoint
[Ctrl] L = Calls dialog to show active procedures; must be in bread
mode
******************
Special Dialog Boxes---- **********
MsgBox( msg [,[type] [,title]] )
a few Types--- Type Meaning
0 Display OK button only
1 Display OK and Cancel buttons
4 Display Yes and No buttons
48 ! (in a circle)
64 i (in a circle)
Example--- Title1A = " Special Info "
MsgBox( "This is an OK box", 0, Title1A )
MsgBox( "This is an OK box", 64, Title1A )
Example--- Title1A = " Special Info "
NL = Chr$(10) & Chr$(13)
Msg = "The text in this file has changed."
Msg = Msg & NL ' end line of text and start a new line
Msg = Msg & "Do you want to save the changes?"
Response = "MsgBox( Msg, 51, Title1A )
Select Case Response
Case 2
Cancel = True
Case 6
' Invoke the Save procedure.
FileSave
Case 7
Cancel = False
End Select
InputBox (prompt [, [title] [, [default] [,xpos, ypos]
[,helpfile, context])
Example--- Dim Answer, DefVal, Msg1, Title
Msg1 = "Enter a value from 1 to 3" ' set prompt
Title = "InputBox Demo" ' set title
DefVal = "1" ' set default
Do
Answer = InputBox( Msg1, Title, DefVal ) ' get user input
Loop Until Answer >= 1 And Answer <= 3
MsgBox = "You entered " & Answer ' display msg
Template---
Dim Answer, DefVal, Msg1, Title1
Msg1 = " " ' set prompt
Title1 = " " ' set title
DefVal = "" ' set default
Answer = InputBox( Msg1, Title, DefVal ) ' get user imput
If Answer = "" Then
'
Else
'
MsgBox " ", 48, " " ' msg, type (!), title
End If
GRAPHICS ░░▒▒░▓
Twips--- 1,440 Twips = 1 (printed) inch; 567 twips = 1 cm
When AutoRedraw is False (the default), place any graphics methods
within the Paint event of the form or container.
If you print to a form or picture box, it is usually best to print to
the picture box. (Use the Print method.)
RGB function for color---
RGB( red, green, blue )
Color Red value Green value Blue value
black 0 0 0
blue 0 0 255
green 0 255 0
cyan 0 255 255
red 255 0 0
yellow 255 255 0
white 255 255 255
Examples--- Form1.BackColor = RGB(0, 255, 0) ' green background
Form1.BackColor = RGB( RED ) ' RED = &HFF&
Movement of Controls---
Left and Top properties---
Examples--- txtField1.Left = txtField1.Left + 200
txtField1.Top = txtField1.Top + 500
Delay---
Example--- place this proc on the main form or in a code module
Sub Delay ()
Dim Start
Dim Check
Start = Timer
Do Until Check >= Start + .15 ' Start time + .15 seconds
Check = Timer ' Timer function
Loop
End Sub
File types ********************************
*.Frm form file
*.Frx binary file that has data for a control on a form
of the same name (example--- Loan1.frm and
Loan1.frx) Some controls have properties that have
binary data as their values, such as the Picture
property of a picture box and image properties of
certain customs controls.
***********************************
OBJECTS (special operations with Objects)
To perform several operations on the same object, you can use the
With...End With statement.
Example---
Private Sub Form_Load()
With cmdProceed
.Caption = "OK"
.Visible = True
.Enabled = True
End With
. . .
End Sub
All controls have default properties. For example, these two
statements are equivalent:
lblHeader1.Caption = "List of Past Due Accounts"
lblHeader1 = "List of Past Due Accounts"
You cannot access default properties this way when the object is
stored in a Variant variable.
You can use the Object Browser to display the classes available
form object libraries and the procedures contained in your project.
See PP. 191-195 PG
Using Object Variables---
See PP. 200-203 PG
syntax--- {Dim |ReDim |Static |Private |Public} variable As
[New] class
Examples---
Dim FormV1 As New frmMain ' declare an object variable of type
' frmMain
Dim anyForm As Form ' generic form variable that can refer
' to any form in the app.
There are Specific object variables and Generic object
variables.
The major difference between the two is that forms can be
visible objects, whereas class modules have no visible
interface.
For adding custom Methods and Properties to forms, see PP.
203-204 in PG.
***********************************
░▒░▒▓▒
DDE Dynamic Data Exchange--- special section
The application that initiates the conversation is called the
destination application, or the destination. The app. responding
to the destination is the source application, or the source.
In VB3, any text box, picture box, or label can be the destination
in a conversion. Any form can be the source.
***********************************
PG = refers to a page in (VB 4) Programmer's Guide
LR = refers to a page in (VB 4) Language Reference